const img2base64 = async img => {
  const getBase64Image = (img) => {
    var canvas = document.createElement("canvas")
    canvas.width = img.width
    canvas.height = img.height
    var ctx = canvas.getContext("2d")
    ctx.drawImage(img, 0, 0, img.width, img.height)
    var ext = img.src.substring(img.src.lastIndexOf(".") + 1).toLowerCase()
    var dataURL = canvas.toDataURL("image/" + ext)
    return dataURL
  }
  var image = new Image()
  image.src = img
  image.setAttribute("crossOrigin", "*") //允许图片跨域请求、必须后台也允许
  //   image.onload = () => {
  var base64 = await getBase64Image(image)
  console.log(base64);
  return base64
  //   }
}
export default img2base64
